function imageSize(url, callback) {

  var cb = function (err, size) {}

  if (callback instanceof Function) {
    cb = callback
  }

  if (typeof url !== 'string') {
    cb(
      new Error('imageSize: url must be a string.')
    )
  }

  var width = 0
  var height = 0
  var img = new Image()
  img.src = url
  img.onerror = function () {
    cb(new Error('image load failed.'))
  }
  img.onload = function () {
    if (img.naturalHeight == null) {
      // not support naturalHeight
      width = img.width
      height = img.height
    } else {
      width = img.naturalWidth
      height = img.naturalHeight
    }

    cb(
      null,
      {
        width: width,
        height: height
      }
    )
  }
}

export default imageSize
